<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.mui-bar-nav {
				background: white;
			}
		</style>
	</head>

	<body>
	
		<nav class="mui-bar mui-bar-tab" id="index">
			<a id="defaultTab" class="mui-tab-item mui-active" href="index-lunbo.html">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-about.html">
				<span class="mui-icon mui-icon-camera"><span class="mui-badge" v-if="count>0">{{count}}</span></span>
				<span class="mui-tab-label">数据采集</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-price.html">
				<span class="mui-icon mui-icon-info"></span>
				<span class="mui-tab-label">市场行情</span>
			</a>

			<a class="mui-tab-item" href="tab-webview-subpage-setting.html">
				<span class="mui-icon mui-icon-person"></span>
				<span class="mui-tab-label">我</span>
			</a>
		</nav>
		<script src="../js/resource/mui.js"></script>
		<script src="../js/resource/vue.js"></script>
		<script src="../js/resource/config.js"></script>
		<script src="../js/index.js"></script>

		<script type="text/javascript" charset="utf-8">
			//mui初始化
			mui.init();
			var subpages = ['index-lunbo.html', 'tab-webview-subpage-about.html','tab-webview-subpage-price.html', 'tab-webview-subpage-setting.html'];
			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};

			var aniShow = {};

			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				for(var i = 0; i < 1; i++) { //这里只加载第一个页面    
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if(i > 0) {
						sub.hide();
					}
					self.append(sub);
				}
			});

			var activeTab = subpages[0];
			var title = document.getElementById("title");
			//选项卡点击事件  
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if(targetTab == activeTab) {
					return;
				}
				//更换标题  
				//title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
				var self = plus.webview.currentWebview();
				var sub = plus.webview.create(targetTab, targetTab, subpage_style);
				self.append(sub);
				//隐藏当前;    
				//plus.webview.hide(activeTab);//这里应该是关闭页面，不知道隐藏与关闭区别有多大    
				plus.webview.close(activeTab);
				//更改当前活跃的选项卡    
				activeTab = targetTab;
			});

			//自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});

			//自定义事件，模拟点击“首页选项卡”
			document.addEventListener('out', function() {
				plus.webview.currentWebview().close();
			});
		</script>
	</body>

</html>